using System;

namespace CoreLibrary {

    public sealed class MathUtil {

        // Returns the largest integral value that is less than or equal to specific value.
        public static int Floor(double value) {
            return (int) Math.Floor(value);
        }

        // Returns the smallest integral value that is greater than or equal to the specified value.
        // This is useful for calculate paging
        public static int Ceiling(double value) {
            return (int) Math.Ceiling(value);
        }

        public static int Round(double value) {
            return (int) Math.Round(value, MidpointRounding.AwayFromZero);
        }

        public static double Round(double value, int numOfDecimals) {
            return Math.Round(value, numOfDecimals);
        }

        public static double Sum(params double[] values) {
            double sum = 0;
            for (int i = 0, iSize = values.Length; i < iSize; i++) {
                 sum += values[i];
            }
            return sum;
        }

        public static double Min(params double[] values) {
            var min = Double.PositiveInfinity;
            for (int i = 0, iSize = values.Length; i < iSize; i++) {
                 min = Math.Min(min, values[i]);
            }
            return min;
        }

        public static double Max(params double[] values) {
            var max = Double.NegativeInfinity;
            for (int i = 0, iSize = values.Length; i < iSize; i++) {
                 max = Math.Max(max, values[i]);
            }
            return max;
        }
        
    }

}